﻿CreatePersonDialog = function($trigger) {
    this.dialog = $("<div id='CreatePerson'></div>");
    this.dialogContent = $("<div id='CreatePersonContent'></div>");
    this.dialog.append(this.dialogContent);
    this.trigger = $trigger;
}

CreatePersonDialog.prototype = {
    init: function() {
        var $createPersonDialog = this;

        // intialize the dialog...
        $createPersonDialog.dialog.dialog({
            autoOpen: false,
            buttons: {
                'Close': function() {
                    $createPersonDialog.dialog.dialog('close');
                }
            },
            height: 450,
            hide: 'slide',
            modal: true,
            title: 'Create Person',
            width: 650
        });

        // initialize the event handler to open the dialog...
        this.trigger.click(function() {
            $createPersonDialog.dialog.dialog('open');
            $.ajax({
                url: '/Person/Create',
                dataType: 'html',
                type: 'get',
                success: function(e) {
                    $createPersonDialog.dialog.dialog('open');
                    $createPersonDialog.dialogContent.html(e);
                },
                error: function(e) {
                    $createPersonDialog.dialog.dialog('close');
                    window.alert('An error was encountered while trying to open the Create Person dialog.');
                }
            });
        });
    }
}